package com.ruoyi.web.controller.video;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.video.VsDramasVideoEpisodes;
import com.ruoyi.system.service.video.IVsDramasVideoEpisodesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.video.VsDramasVideoOrder;
import com.ruoyi.system.service.video.IVsDramasVideoOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 视频订单Controller
 * 
 * @author zzx
 * @date 2024-04-30
 */
@Api(tags = "视频订单")
@RestController
@RequestMapping("/video/order")
public class VsDramasVideoOrderController extends BaseController
{
    @Autowired
    private IVsDramasVideoOrderService vsDramasVideoOrderService;

    @Autowired
    private IVsDramasVideoEpisodesService vsDramasVideoEpisodesService;

    /**
     * 查询视频订单列表
     */
    @ApiOperation("查询视频订单列表")
    @GetMapping("/list")
    public TableDataInfo list(VsDramasVideoOrder vsDramasVideoOrder)
    {
        startPage();
        List<VsDramasVideoOrder> list = vsDramasVideoOrderService.selectVsDramasVideoOrderList(vsDramasVideoOrder);
        return getDataTable(list);
    }

    /**
     * 导出视频订单列表
     */
//    @ApiOperation("导出视频订单列表")
    @Log(title = "视频订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasVideoOrder vsDramasVideoOrder)
    {
        List<VsDramasVideoOrder> list = vsDramasVideoOrderService.selectVsDramasVideoOrderList(vsDramasVideoOrder);
        ExcelUtil<VsDramasVideoOrder> util = new ExcelUtil<VsDramasVideoOrder>(VsDramasVideoOrder.class);
        util.exportExcel(response, list, "视频订单数据");
    }

    /**
     * 获取视频订单详细信息
     */
//    @ApiOperation("获取视频订单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vsDramasVideoOrderService.selectVsDramasVideoOrderById(id));
    }

    /**
     * 新增视频订单
     */
    @ApiOperation("新增视频订单")
    @Log(title = "视频订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasVideoOrder vsDramasVideoOrder)
    {
        int i = vsDramasVideoOrderService.insertVsDramasVideoOrder(vsDramasVideoOrder);
        if (i == -1) {
            return error("余额不足！");
        }
        if (i == -2) {
            return error("您可以免费观看，无需购买！");
        }
        Integer id = Math.toIntExact(vsDramasVideoOrder.getEpisodeId());
        VsDramasVideoEpisodes episodes = vsDramasVideoEpisodesService.selectVsDramasVideoEpisodesById(id);
        Map map = new HashMap<>();
        map.put("video",episodes.getVideo());
        return success(map);
    }

    /**
     * 修改视频订单
     */
//    @ApiOperation("修改视频订单")
    @Log(title = "视频订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasVideoOrder vsDramasVideoOrder)
    {
        return toAjax(vsDramasVideoOrderService.updateVsDramasVideoOrder(vsDramasVideoOrder));
    }

    /**
     * 删除视频订单
     */
//    @ApiOperation("删除视频订单")
    @Log(title = "视频订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vsDramasVideoOrderService.deleteVsDramasVideoOrderByIds(ids));
    }
}
